package zifuchuan.zifuchuanpipei;

public class _03暴力KMP {
    public static void main(String[] args) {
        int index = index("babababcbabababb", "bababb");
        System.out.println(index);
    }

    public static int index(String s, String p) {
        int i = 0;
        int j = 0;
        int scan = i;
        while (scan < s.length()) {
            if (s.charAt(scan) == p.charAt(j)) {
                j++;
                scan++;
                if (j == p.length()) {
                    return i;
                }
            } else {
                i += 1;
                scan = i;
                j = 0;
            }
        }
        return -1;
    }
}
